﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class DemandeCorrectionForm : Form
    {
        public List<Type_Correction> TypesAjoutes = new List<Type_Correction>();
        public List<Type_Correction> TypesSelectionnes = new List<Type_Correction>();
        public DemandeCorrectionForm()
        {
            
            InitializeComponent();
            RAMEDEntities1 CONTEXT = new RAMEDEntities1();
            TypesSelectionnes = CONTEXT.Type_Correction.ToList();
            listBoxselectionne.DataSource = TypesSelectionnes;
            listBoxselectionne.DisplayMember = "description";
            
            CONTEXT = SingletonContext.GetContext();
            

            comboBoxresp.DataSource = CONTEXT.Responsables;
            comboBoxresp.DisplayMember = "nom_prenom_responsable";

            comboBoxannexe.DataSource = CONTEXT.Annexe_administratif;
            comboBoxannexe.DisplayMember = "nom_annexe_administratif";
        }

        private void DemandeCorrectionForm_Load(object sender, EventArgs e)
        {

        }

        private void btnajou_Click(object sender, EventArgs e)
        {
            RAMEDEntities1 Context = SingletonContext.GetContext();
              CORRECTION correctionajoute = new CORRECTION();
            correctionajoute.Num_dossier = utitlitaire.CasterString(txtnumdossier.Text);
            correctionajoute.Nom = txtnom.Text;
            correctionajoute.Prénom = txtprenom.Text;
            correctionajoute.Cin = txtcin.Text;

            correctionajoute.Date_demande_correction = dateTimePickercorr.Value;
            correctionajoute.id_Responsable = ((Responsable)comboBoxresp.SelectedValue).id_responsable;
            //Responsable responsable = (Responsable)comboBoxresp.SelectedValue;
            //borer.id_responsable = responsable.id_responsable;
            correctionajoute.id_annexe_administratif = ((Annexe_administratif)comboBoxannexe.SelectedValue).id_annexe_administratif;
            
             Context.CORRECTIONs.AddObject(correctionajoute);
            foreach (Type_Correction tp in TypesAjoutes)
            {
                    Association_Correction_Type ast = new Association_Correction_Type();
                    ast.id_Type_Correction = tp.id_Type_Correction;
                   
                    correctionajoute.Association_Correction_Type.Add(ast);
             
            }
            //correctionajoute.id_Responsable = responsable.id_responsable;
           
            Context.SaveChanges();
            this.Dispose();

           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void txttypecorr_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Type correction est obligatoire", txtnumdossier, e, errorProvider1);
        }

       

        private void txtnumdossier_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Nomero dossier est obligatoire", txtnumdossier, e, errorProvider1);
        }

        private void txtnom_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Nom est obligatoire", txtnom, e, errorProvider1);
        }

        private void txtprenom_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Prénom est obligatoire", txtprenom, e, errorProvider1);
        }

        private void txtcin_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs CIN est obligatoire", txtcin, e, errorProvider1);
        }


        private void comboBoxannexe_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Button21_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void comboBoxresp_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
        }

        private void btn1_Click(object sender, EventArgs e)
        {
            List<Type_Correction> type_corrections = new List<Type_Correction>();
            type_corrections = listBoxselectionne.SelectedItems.Cast<Type_Correction>().ToList();



            foreach (Type_Correction tp in type_corrections)
            TypesSelectionnes.Remove(tp);
            listBoxselectionne.DataSource = null;
            listBoxselectionne.DataSource = TypesSelectionnes;
            listBoxselectionne.DisplayMember = "description";
            listBoxselectionne.Refresh();

            TypesAjoutes.AddRange(type_corrections);

            listBoxAjouter.DataSource = null;
            listBoxAjouter.DataSource = TypesAjoutes;
            listBoxAjouter.DisplayMember = "description";
            listBoxAjouter.Refresh();

        }

        private void btn2_Click(object sender, EventArgs e)
        {
            List<Type_Correction> type_corrections = new List<Type_Correction>();
            type_corrections = listBoxAjouter.SelectedItems.Cast<Type_Correction>().ToList();


            foreach (Type_Correction tp in type_corrections)
                TypesAjoutes.Remove(tp);
            listBoxAjouter.DataSource = null;
            listBoxAjouter.DataSource = TypesAjoutes;
            listBoxAjouter.DisplayMember = "description";
            listBoxAjouter.Refresh();

            TypesSelectionnes.AddRange(type_corrections);

            listBoxselectionne.DataSource = null;
            listBoxselectionne.DataSource = TypesSelectionnes;
            listBoxselectionne.DisplayMember = "description";
            listBoxselectionne.Refresh();
        }

        private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        }

        

        
    }


 
